using System;
using System.Diagnostics;
using System.Collections.Generic;
using org.tmatesoft.svn.core;
using org.tmatesoft.svn.core.wc;

namespace Subsync.Core.Subversion
{
	/// <summary>
	/// Author: Zhang Andy
	/// </summary>
	public enum Resolution
    {
		MineFully,
		TheirsFully
	}
	
	class SVNResolve : CommandBase
    {
        // Initialise variables with default settings.
        private java.io.File filePath; //path of file to be marked resolved
        private SVNDepth depth = SVNDepth.INFINITY;
        private SVNConflictChoice choice = SVNConflictChoice.POSTPONE;
        //Available choices - BASE, MERGED, MINE_CONFLICT, MINE_FULL, THEIRS_CONFLICT, THEIRS_FULL

        // Minimal Constructor
        public SVNResolve(string path, Resolution ch)
        {
            Debug.WriteLine("SVNResolved Minimal Constructor.");
            this.filePath = new java.io.File(path);
            switch (ch)
            {
                case Resolution.MineFully:
                    this.choice = SVNConflictChoice.MINE_FULL;
                    break;
                case Resolution.TheirsFully:
                    this.choice = SVNConflictChoice.THEIRS_FULL;
                    break;
            }
        }

        // Full Constructor
        public SVNResolve(string path, SVNDepth depth, Resolution ch)
        {
            Debug.WriteLine("SVNResolved Full Constructor.");
            this.filePath = new java.io.File(path);
            this.depth = depth;
            switch (ch)
            {
                case Resolution.MineFully:
                    this.choice = SVNConflictChoice.MINE_FULL;
                    break;
                case Resolution.TheirsFully:
                    this.choice = SVNConflictChoice.THEIRS_FULL;
                    break;
            }
        }

        public override void Execute()
        {
            Debug.WriteLine("SVNResolved Execution");

            //library setup
            Tools.SetupLibrary();

            //load up the clients
            SVNClientManager cm = SVNClientManager.newInstance();
            SVNWCClient wc = cm.getWCClient();

            try
            {
                wc.doResolve(filePath, depth, choice);
            }
            catch (SVNException e)
            {
                throw new SVNExecuteException(e.getMessage());
            }
        }
    }
}
